package task;

import java.util.LinkedList;

/**
 *
 * @author pdv
 *
 */
public class TaskQueue {

	private LinkedList<Task> queue = new LinkedList<Task>();
	
	/**
	 * 
	 * @param task
	 */
	public synchronized void feedTask(Task task) {
		if (task == null)
			throw new RuntimeException("������Worker���null����");
		if (queue.size()>this.maxlen)
			queue.clear();
		queue.add(task);
		
	}
	/**
	 * ��ȡ�������
	 * @return
	 */
	public synchronized int taskCount() {
		return this.queue.size();
	}
	/**
	 *
	 * @return
	 */
	public synchronized Task retriveTask() {
		if (queue.size() == 0)
			return null;
		return queue.remove();
	}
	private int maxlen=5000;
	public void setMaxLen(int maxlen){
		this.maxlen=maxlen;
	}
}
